/*
 * @Author: your name
 * @Date: 2021-04-29 11:03:33
 * @LastEditTime: 2021-04-29 15:52:05
 * @LastEditors: Please set LastEditors
 * @Description: In User Settings Edit
 * @FilePath: \offer20k\项目代码\management\src\app.ts
 */

import { RequestConfig } from "umi";
import { createLogger } from "redux-logger";
import StoreContext from '@/context/storeContext'
import store from '@/store';
import React from 'react';
const baseURL = '';
export const request: RequestConfig = {
    timeout: 3000,
    //   初始配置
    errorConfig: {},
    //   请求拦截器
    requestInterceptors: [
        (url, options) => {
            if (!/\/\//.test(url)){
            url = baseURL + url;
        }
            // let headers = {};
            return {
                url,
                options
            };
        },
    ],

    //   响应拦截器
    responseInterceptors: [response => {
        const codeMaps: { [key: string]: string } = {
            400: '错误请求',
            403: '请求禁止访问',
            404: '请求资源不存在',
            500: '服务器内部错误',
            502: '网关错误',
            503: '服务不可用，服务器暂时过载或维护',
            504: '网关超时',
        };
        if (response.status !== 200) {
            // debugger
            console.warn(codeMaps[response.status]);
        }
        return response;
    }],
};
// dva配置
export const dva = {
    config: {
        onAction: createLogger(),
        onError(err: Error) {
            console.log(err);
        },
    },
};

export function rootContainer(container: any) {
    return React.createElement(StoreContext.Provider, {value: store}, container);
}

